package com.autotest.nore.common.data;

import java.util.UUID;
import java.util.Random;


public class StringData {
    // 生成UUID
    public static String uuid() {
        return UUID.randomUUID().toString();
    }

    // 生成NanoID（这里简化处理，实际的Nano ID生成可能更复杂）
    public static String nanoId() {
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 10; i++) {
            int digit = random.nextInt(36);
            if (digit < 10) {
                sb.append(digit);
            } else {
                sb.append((char) ('a' + digit - 10));
            }
        }
        return sb.toString();
    }

    // 生成字母字符串
    public static String alpha(String lengthStr) {
        int length=Integer.parseInt(lengthStr);
        String letters = "abcdefghijklmnopqrstuvwxyz";
        StringBuilder sb = new StringBuilder(length);
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            sb.append(letters.charAt(random.nextInt(letters.length())));
        }
        return sb.toString();
    }

    // 生成数字字符串
    public static String numeric(String lengthStr) {
        int length=Integer.parseInt(lengthStr);
        StringBuilder sb = new StringBuilder(length);
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            sb.append(random.nextInt(10));
        }
        return sb.toString();
    }

    // 生成字母或数字字符串
    public static String alphanumeric(String lengthStr) {
        int length=Integer.parseInt(lengthStr);
        String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        StringBuilder sb = new StringBuilder(length);
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            sb.append(chars.charAt(random.nextInt(chars.length())));
        }
        return sb.toString();
    }

    // 生成符号字符串
    public static String symbol(String lengthStr) {
        int length=Integer.parseInt(lengthStr);
        String symbols = "!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?";
        StringBuilder sb = new StringBuilder(length);
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            sb.append(symbols.charAt(random.nextInt(symbols.length())));
        }
        return sb.toString();
    }

    // 从字符生成字符串
    public static String fromCharacters(String characters, String lengthStr) {
        int length=Integer.parseInt(lengthStr);
        StringBuilder sb = new StringBuilder(length);
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            sb.append(characters.charAt(random.nextInt(characters.length())));
        }
        return sb.toString();
    }

    // 二进制字符串
    public static String binary(String lengthStr) {
        int length=Integer.parseInt(lengthStr);
        String binaryChars = "01";
        StringBuilder sb = new StringBuilder(length);
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            sb.append(binaryChars.charAt(random.nextInt(binaryChars.length())));
        }
        return sb.toString();
    }
    // 八进制字符串
    public static String octal(String lengthStr) {
        int length=Integer.parseInt(lengthStr);
        String octalChars = "01234567";
        return fromCharacters(octalChars, String.valueOf(length));
    }
    // 十六进制字符串
    public static String hexadecimal(String lengthStr) {
        int length=Integer.parseInt(lengthStr);
        String hexChars = "0123456789abcdef";
        return fromCharacters(hexChars, String.valueOf(length));
    }


}
